package com.homework.action;

import java.util.HashMap;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.apache.struts2.interceptor.ServletRequestAware;
import org.json.JSONObject;

import com.homework.service.EvaluationService;
import com.opensymphony.xwork2.ActionSupport;

public class EvaluationAction extends ActionSupport  implements ServletRequestAware{

	/**
	 * 
	 */
	private static final long serialVersionUID = -1113782457482141943L;
	
	private HttpServletRequest request = null;
	private EvaluationService evaluationService;
	public Map<String, String> map = new HashMap<String, String>();




	
	@Override
	public void setServletRequest(HttpServletRequest arg0) {
		// TODO Auto-generated method stub
		request = arg0;//这个要自己写，糗
	}
	
	public EvaluationAction(){
		evaluationService = new EvaluationService();
	}
	
	public String execute(){
		String jsonofTitle = request.getParameter("request");
		String homeworkId = request.getParameter("homeworkId");
		JSONObject json = new JSONObject();
		
		if(evaluationService.saveEvaluation(jsonofTitle,homeworkId)){
			json.put("result", "success");
			map.put("result", "success");
			return "success";
		}
		else{
			json.put("result", "fail");
			map.put("result", "fail");
			return "fail";
		}
	}

}
